package com.qf.controller;/*
 *徐韬
 *2021/11/2
 *19:22
 */

import com.alibaba.druid.sql.visitor.functions.If;
import com.github.pagehelper.PageInfo;
import com.qf.cache.filterCache;
import com.qf.dto.R;
import com.qf.pojo.TFilters;
import com.qf.service.filterService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/filter")
@Api(tags = "过滤器管理")
public class filterController {
    private filterCache filterCache;
@Autowired
    public void setFilterCache(com.qf.cache.filterCache filterCache) {
        this.filterCache = filterCache;
    }

    private filterService filterService;
@Autowired
    public void setFilterService(com.qf.service.filterService filterService) {
        this.filterService = filterService;
    }

    @GetMapping("/showAll")
    public R showAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "2") Integer pageSize){
        PageInfo<TFilters> pageInfo = filterService.showAll(pageNum, pageSize);

        return R.setOk(pageInfo);
    }
    @GetMapping("/show/{id}")
    public R show(@PathVariable Long id){
        TFilters filters = filterCache.getById(id);
        return R.setOk(filters);
    }
    @PostMapping("/add")
    public R add(@RequestBody TFilters tFilters){
         filterService.addFilter(tFilters);
         return R.setOk();
    }
    @DeleteMapping("/delete")
    public R delete(@RequestBody Map map){
        List<Integer> ids =(List<Integer>) map.get("ids");
        filterService.deleteByids(ids);
        return R.setOk();
    }

}
